package com.powergisol.gis.util;

import java.io.*;
import java.nio.channels.FileChannel;


public class FileCopy {

    /**
     * 复制文件内容
     * @param f1 原始文件
     * @param f2 目标文件
     * @throws IOException
     */
    public static void copy(File f1, File f2) throws IOException {
        // 检测是否存在目录
        if (!f2.getParentFile().exists()) {
            f2.getParentFile().mkdirs();
        }
        if(f2.exists()){
            return;
        }
            try {
                FileInputStream fileInputStream = new FileInputStream(f1);
                FileOutputStream fileOutputStream = new FileOutputStream(f2);
                byte[] b = new byte[1024];//0-1024
                int count = fileInputStream.read(b, 0, 1024);
                while (count > 0) {
                    fileOutputStream.write(b, 0, count);
                    count = fileInputStream.read(b, 0, 1024);
                    System.out.println(count);
                }
                fileInputStream.close();
                fileOutputStream.close();
                System.out.println("文件复制成功！");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    public static void main(String[] args) throws IOException {
        copy(new File("F:\\gc\\all1.tif"),new File("F:\\gc\\layer.tif"));
    }

}
